using System.Windows;
using System.Windows.Browser;

namespace MoonRainbow.Input.Mouse
{
    internal class NotIEMouseRightButtonDownBehavior : MouseBehavior
    {
        public NotIEMouseRightButtonDownBehavior()
        {
            HtmlPage.Document.AttachEvent("mousedown", MouseDown);
        }

        private void MouseDown(object sender, HtmlEventArgs e)
        {
            if (e.MouseButton != MouseButtons.Right) return;
            var point = GetPosition(HtmlPage.Plugin.Parent);
            MouseManager.NotIEHuckElement.SetAttribute("style",
                                                        "width:100%;height:100%;position:absolute;left:0;top:0;zIndex:100");
            HtmlPage.Document.Body.AppendChild(MouseManager.NotIEHuckElement);
            if (point.X > e.ClientX ||
                point.X + Application.Current.Host.Content.ActualWidth < e.ClientX ||
                point.Y > e.ClientY ||
                point.Y + Application.Current.Host.Content.ActualHeight < e.ClientY)
                return;
            InvokeMouseEventDetected(new MouseEventDetectedEventArgs(new Point(e.ClientX - point.X, e.ClientY - point.Y)));
        }
    }
}